//
//  AddBandCardViewController.m
//  NewPro
//
//  Created by RYX on 2018/10/12.
//  Copyright © 2018年 何荧红. All rights reserved.
//

#import "AddBandCardViewController.h"
//#import "ConfirmBandCardViewController.h"
#import "AddBandCardInfoViewController.h"
#import "WYIDScanViewController.h"
#import "BankCarList.h"
#import "BandCardAddParametersModel.h"

@interface AddBandCardViewController ()
{
    
    __weak IBOutlet UITextField *bandIdTf;
}
@end

@implementation AddBandCardViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setNavBarWithTitle:@"添加银行卡"];
    
    bandIdTf.keyboardType = UIKeyboardTypeNumberPad;
}

#pragma mark - 下一步
- (IBAction)onNextBtn:(UIButton *)sender {
    
    [self.view endEditing:YES];
    
    if (bandIdTf.text.length <= 0) {
        
        return [self showMBPError:@"请填写银行卡号"];
    }
    
    if (![bandIdTf.text checkCardNo:bandIdTf.text]) {
        
        return [self showMBPError:@"请填写正确银行卡号"];
    }
    
    [BankCarList sharedInstance].addParametersModel.cardNumber = bandIdTf.text;
    
    AddBandCardInfoViewController *VC = [[AddBandCardInfoViewController alloc] init];
    [self.navigationController pushViewController:VC animated:YES];
    
}

#pragma mark - 扫描银行卡，获取卡号
- (IBAction)onGetBandCardBtn:(UIButton *)sender {
    
    [self.view endEditing:YES];
    
    WYIDScanViewController *VC = [[WYIDScanViewController alloc] initWithCarInfo: CardIDBank];
    
    
    [VC scanDidFinishCarInfo:^(CardType status, WYScanResultModel *scanModel) {
        
        NSString *str = [scanModel.bankNumber stringByReplacingOccurrencesOfString:@" " withString:@""];
        
        self->bandIdTf.text = str;
        
        [BankCarList sharedInstance].addParametersModel.cardNumber = str;
        [BankCarList sharedInstance].addParametersModel.bankName = scanModel.bankName;
        
    }];
    
    [self.navigationController pushViewController:VC animated:YES];
    
}



@end
